<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../css/font.css">
    <link rel="stylesheet" href="../css/xadmin.css">
    <script type="text/javascript" src="../js/jquery-3.2.1.min.js"></script>
    <script src="../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../lib/layui/lay/modules/jquery.js"></script>
    <script type="text/javascript" src="../js/xadmin.js"></script>

    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<!--自定义css -->
<style type="text/css">
/*<!--所以td中的文字居中-->*/
    td {
        text-align: center;
    }

</style>

<body>
<div class="x-nav">
            <span id="navigate" class="layui-breadcrumb">
                <a href="">首页</a>
                <a href="">演示</a>
                <a>
                    <cite>导航元素</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="refresh()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px">ဂ</i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">

            <div class="layui-card">
            <div class="layui-row" style="margin-top: 20px"><form class="layui-form layui-col-md12 x-so" action="/order/list">
                <div class="layui-input-inline">
                    <input style="width: 300px"  type="text" name="inputName"   placeholder="请输入订单号/地址/收货人查询" autocomplete="off" class="layui-input">
                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                </div>
            </form>

            </div>

                <div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()">
                        <i class="layui-icon"></i>批量删除</button>

                        <span  class="x-right" style="font-size: larger;margin-right: 10px;line-height:40px">
                            共有数据： <span th:text="${totalNum}" style="font-size: large;margin-right: 4px;color: #7a45e5"></span>条
                         </span>

<!--                    <button class="layui-btn" onclick="xadmin.open('添加用户','./order-add.html',800,600)">-->
<!--                        <i class="layui-icon"></i>添加</button></div>-->

                <div class="layui-card-body ">
                    <table class="layui-table layui-form">

                        <thead>
                        <tr >
                            <th style="text-align:center;">
                                <input type="checkbox" id="All" name="getAll" lay-skin="primary" class="layui-unselect header layui-form-checkbox"></th>
                            <th style="text-align:center;">订单编号</th>
                            <th style="text-align:center;">收货人</th>
                            <th style="text-align:center;">收货人电话</th>
                            <th style="text-align:center;">收货地址</th>
<!--                            <th>收货人留言</th>-->
                            <th style="text-align:center;">收货人邮编</th>
                            <th style="text-align:center;">配送物流</th>
                            <th style="text-align:center;">支付状态</th>
                            <th style="text-align:center;">下单时间</th>
<!--                            <th>邮费</th>-->
<!--                            <th>商品金额</th>-->
<!--                            <th>个数</th>-->
<!--                            <th>应付金额</th>-->
                            <th style="text-align:center;">详细订单</th>
                            <th style="text-align:center;">操作</th></tr>
                        </thead>

                        <tbody id="div">
                        <tr th:each="list:${orderList}">
                            <td th:text="${list.id}" style="display: none"></td>
                            <td >
                                <input th:value="${list.id}"  id="orderId" name="ck" type="checkbox" lay-skin="primary" class="layui-unselect header layui-form-checkbox"></td>
                            <td th:text="${list.orderCode}"></td>
                            <td th:text="${list.receiver}"></td>
                            <td th:text="${list.mobile}"></td>
                            <td th:text="${list.address}"></td>
<!--                            <td th:text="${list.userMessage}"></td>-->
                            <td th:text="${list.post}"></td>
                            <td th:text="${list.postMethod}"></td>

                            <td th:if="${list.status=='1'}" style="background-color:red;font-weight: bold;font-size: 16px">未付款</td>
                            <td th:if="${list.status=='2'}" style="background-color: chartreuse;font-weight: bold;font-size: 16px">已付款</td>
                            <td th:if="${list.status=='3'}" style="background-color: #bd2c00;font-weight: bold;font-size: 16px">未发货</td>
                            <td th:if="${list.status=='4'}" style="background-color: #1E9FFF;font-weight: bold;font-size: 16px">已发货</td>
                            <td th:if="${list.status=='5'}" style="background-color: blueviolet;font-weight: bold;font-size: 16px">已完成</td>
                            <td th:if="${list.status=='6'}" style="background-color: #FFB800;font-weight: bold;font-size: 16px">已取消</td>
                            <td th:text="${#dates.format(list.createDate, 'yyyy-MM-dd HH:mm:ss')}"></td>
<!--                            <td th:text="${list.postage}"></td>-->
<!--                            <td th:text="${list.orderItems.total}"></td>-->
<!--                            <td th:text="${list.orderItems.number}"></td>-->
<!--                            <td th:text="${list.orderItems.total*list.orderItems.number+list.postage}"></td>-->

                            <td class="td-status" style="text-align:center">
                                <span class="layui-btn layui-btn-normal layui-btn-mini" onclick="showOrders(this)">详细订单</span></td>

                            <td class="td-manage">
                                <a title="编辑"  onclick="x_admin_shows('编辑订单','/order/updateOrder',800,500,this)" href="javascript:;">
                                    <i class="layui-icon">&#xe642;</i>
                                </a>
                                <a title="取消订单" onclick="member_del(this,'要删除的id')" href="javascript:;">
                                    <i class="layui-icon">&#xe640;</i></a>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>

                <div class="layui-card-body ">
                    <div class="page">
                        <!--上一页-->
                        <a class="prev" th:if="${pageInfo.pageNum}>1" th:href="@{'/order/list?currentPage='+${pageInfo.prePage}}">&lt;&lt;</a>
                        <!--当前页，选中为红色，未选中为黑色-->
                        <th:block th:each="num:${pageInfo.navigatepageNums}" >
                            <a th:class="${num==pageInfo.pageNum}" th:href="@{'/order/list?currentPage='+${num}}" th:text="${num}" th:if="${num}==${pageInfo.pageNum}" style="color: red" ></a>
                            <a th:class="${num==pageInfo.pageNum}" th:href="@{'/order/list?currentPage='+${num}}" th:text="${num}" th:if="${num}!=${pageInfo.pageNum}" style="color: black" ></a>
                        </th:block>
                        <!--下一页-->
                        <a class="next" th:if="${pageInfo.pageNum}<${pageInfo.pages}" th:href="@{'/order/list?currentPage='+${pageInfo.nextPage}}">&gt;&gt;</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
</body>
<script>


        // 获取所有复选框
        var cks = $('input[name=ck]');

        // 全选
        $('[name=getAll]').click(function () {
            if ($(this).is(':checked')) {
                cks.each(function () {
                    $(this).prop('checked', true);
                });
            } else {
                cks.each(function () {
                    $(this).prop('checked', false);
                });
            }


            if(cks.is(':checked')){
                $('input[name=getAll]').prop('checked', true);
            }else {
                $('input[name=getAll]').prop('checked', false);
            }
        })



    //刷新
    function refresh(){
        location.href = '/order/list'
    }
    //
    function showOrders(obj){
        var oId = $(obj).parents("tr").find("td").eq(0).text();
        location.href = '/order/orderDetail?oId='+oId;
        // $(window.parent.document).find("#par").after("  <li lay-id=\"14\" class=\"layui-this\">\n" +
        //                          "订单列表<i class=\"layui-icon layui-unselect layui-tab-close\">ဆ</i>\n" +
        //                      "</li>")
    }

    layui.use(['laydate', 'form'],
    function() {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });
    });

//模态框
    function x_admin_shows(title,url,w,h,obj){
        var oId = $(obj).parents("tr").find("td").eq(0).text();
        var newUrl = url+"?oId="+oId;
        // alert(questionId)
        if (title == null || title == '') {
            title=false;
        };
        if (url == null || url == '') {
            url="404.html";
        };
        if (w == null || w == '') {
            w=($(window).width()*0.9);
        };
        if (h == null || h == '') {
            h=($(window).height() - 50);
        };
        layer.open({
            type: 2,
            area: [w+'px', h +'px'],
            fix: false, //不固定
            maxmin: true,
            shadeClose: true,
            shade:0.4,
            title: title,
            content: newUrl
        });
    }

/*用户-停用*/
function member_stop(obj, id) {
    layer.confirm('确认要停用吗？',
        function(index) {

            if ($(obj).attr('title') == '启用') {

                //发异步把用户状态进行更改
                $(obj).attr('title', '停用');
                $(obj).find('i').html('&#xe62f;');

                $(obj).parents("tr").find(".td-status").find('span').addClass('layui-btn-disabled').html('已停用');
                layer.msg('已停用!', {
                    icon: 5,
                    time: 1000
                });

            } else {
                $(obj).attr('title', '启用');
                $(obj).find('i').html('&#xe601;');

                $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-disabled').html('已启用');
                layer.msg('已启用!', {
                    icon: 5,
                    time: 1000
                });
            }

        });
}

/*订单-删除*/
function member_del(obj, id) {

    var orderId = $(obj).parents("tr").find("td").eq(0).text();
    layer.confirm('确认要取消吗？',
        function(index) {
        $.ajax({
            url:"/order/deleteOrderById",
            async:false ,//异步
            type:"get",
            data:{orderId:orderId},
            dataType:"json",
            success:function(result){
                if(result=="1"){
                    //发异步删除数据
                    $(obj).parents("tr").remove();
                    layer.msg('已取消!', {
                        icon: 1,
                        time: 1000
                    });
                }else{
                    layer.msg('取消失败!', {
                        icon: 2,
                        time: 1000
                    });
                }

            },
            error:function (result) {
                // layer.msg("ajax请求失败",{icon:2,time:1000})
                layer.msg("取消失败",{icon:2,time:1000})
            }
        })


        });
}

//订单批量删除
function delAll(argument) {
    var oIds="";
    $('input[type=checkbox]:checked').each(function() {
        oIds+=$(this).val()+",";
        //给选中复选框加样式,自定义样式
        $(this).parents("tr").addClass("dddd");
    });
    alert(oIds);

    var data = tableCheck.getData();

    layer.confirm('确认要取消这些订单吗？' + oIds, function (index) {
        $.ajax({
            url: "/order/deleteSomeByIds",
            type: "post",
            data:
                {
                    oIds: oIds,
                },
            datatype: "json",
            success: function (data) {
                if (data == "1") {
                    //捉到所有被选中的，发异步进行删除
                    layer.msg('取消成功', {icon: 1});
                    $(".dddd").remove();
                } else {
                    layer.msg('请选择要取消的订单!', {icon: 2, time: 1000});
                }
            }
        })
    });
}

</script>

</html>